<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>React05</title>
  <style>
    button {
      margin-inline: 10px;
    }
  </style>

</head>

<body>
  <div class="container"></div>
  <!-- react核心库 -->
  <script src="./js/react.development.js"></script>
  <!-- react拓展库 用于支持react操作dom -->
  <script src="./js/react-dom.development.js"></script>
  <script src="./js/prop-types.js"></script>
  <script src="./js/babel.min.js"></script>

  <script type="text/babel">
    class Demo extends React.Component {
      render() {
        return (
          <div>
            { /* 内联ref */ }
            <input type="text" placeholder="点击按钮显示数据" ref={c => this.inputRef01 = c} />
            <button onClick={this.showLeft}>点我提示左侧的数据</button>
            { /* 方法ref */ }
            <input type="text" placeholder="失去焦点显示数据" onBlur={this.showRight} ref={this.saveInput} />
          </div>
        )
      } 
      // createRef
      // 专人专用的容器 { current: xxx }   this.myRef.current.value
      // myRef = React.createRef()

      showLeft = () => {
        // alert(this.refs.inputRef1.value)
        alert(this.inputRef01.value)
      }

      saveInput = (c) => {
        this.inputRef2 = c
      }

      showRight = () => {
        // alert(this.refs.inputRef2.value)
        alert(this.inputRef2.value)
      }
    }

    ReactDOM.render(<Demo />, document.querySelector('.container'))
  </script>
</body>

</html>